package controller

/*
 * @Desc: 用户管理
 * @author: bsyz
 * @version: v1.0.0
 */

import (
	"github.com/PhlexTheCharr/GoFurry-framework/apps/system/user/models"
	"github.com/PhlexTheCharr/GoFurry-framework/apps/system/user/service"
	"github.com/PhlexTheCharr/GoFurry-framework/common"
	"github.com/gin-gonic/gin"
)

type userApi struct{}

var UserApi *userApi

func init() {
	UserApi = &userApi{}
}

// @Summary 登录请求
// @Schemes
// @Description 登录
// @Tags System-user
// @Accept json
// @Produce json
// @Param body body models.UserLoginRequest true "请求body"
// @Success 200 {object} common.ResultData
// @Router /api/system/user/login [Post]
func (api *userApi) Login(context *gin.Context) {
	var req models.UserLoginRequest
	if err := context.BindJSON(&req); err != nil {
		common.NewResponse(context).Error("参数错误")
	}
	token, err := service.GetUserService().Login(req)
	if err != nil {
		common.NewResponse(context).Error(err.GetMsg())
		return
	}
	var data = map[string]interface{}{
		"token": token,
	}
	common.NewResponse(context).SuccessWithData(data)
}
